﻿<cfscript>
/** 
* @hint "教学质量评价相关监听器"
*/ 

component 
	extends="MachII.framework.Listener" 
	displayname="acadmicManager.listeners.vote.suggestListener" 
	output=false 
	depends="sessionAdvice, datetimeAdvice, sequenceEvaluateComment" 
	{
	
	/**
	* @hint "Configures this listener as part of the Mach-II framework"
	*/
	public void function configure() output=false {} 
	
	/**
	* @hint "添加学生对教师文字评价"
	* 
	* @event "MachII Event Object"
	*/
	public void function createSuggest( required MachII.framework.Event event ) output=false {
		
		var sequenceEvaluateComment = getsequenceEvaluateComment();
		var sessionAdvice = getsessionAdvice();
		
		var sql = "";
		var queryObj = "";
		
		/* 学期代码 */
		var termId = event.getArg("TID");
		/* 教学班号 */
		var taskId = event.getArg("TSK");

		/* 主讲教师职工号 */
		var teacherId = event.getArg("TeacherID");
		/* 课程号 */
		var courseId = event.getArg("CourseID");
		/* 标题 */
		var title = event.getArg("Title");
		/* 意见内容 */
		var suggest = event.getArg("CourseComment");
		
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
			
			if ( trim(suggest) neq "无" and len(trim(suggest)) gt 10 ) {
			
				/* 当前日期时间字符串 */
				var currentDateTime = getdatetimeAdvice().getCurrentDatetimeString();
			
				/* 学号 */
				var studentId = sessionAdvice.getAutherUserID();
			
				sequenceEvaluateComment.setTermID( termId );
				sequenceEvaluateComment.setStudentID( studentId );
			
				/* 消息序号 */
				var messageId = sequenceEvaluateComment.getID();
				
				writeLog( text=messageId);
				writeLog( text=termId);
				writeLog( text=studentId);
				writeLog( text=teacherId);
				writeLog( text=courseId);
				writeLog( text=taskId);
				writeLog( text=title);
				writeLog( text=suggest);
				writeLog( text=currentDateTime);
			
				sql = "INSERT INTO t_evaluate_comment 
						( msg_id, term_id, stu_id, tch_id, cid, task_id, title, suggest, suggest_date, reply, reply_date, is_public, is_feed ) 
						VALUES 
						( :messageId, :termId, :studentId, :teacherId, :courseId, :taskId, :title, :suggest, :currentDateTime, :reply, :currentDateTime, '0', '0' ) ";
			
				queryObj = new Query( datasource=application.dnsMaster );
				
				queryObj.addParam( name="messageId", value=messageId, cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="termId", value=termId, cfsqltype="cf_sql_char" );
				queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="teacherId", value=teacherId, cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="courseId", value=courseId, cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="title", value=title, cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="suggest", value=suggest, cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="currentDateTime", value=currentDateTime, cfsqltype="cf_sql_char" );
				queryObj.addParam( name="reply", value="NOPE", cfsqltype="cf_sql_varchar" );
				

				queryObj.execute( sql=sql );
			
			}
			
		}
		
	}
	
}

</cfscript>